package com.ygqh.baby.service.impl;
import java.util.List;

import  com.ygqh.baby.ao.QueryInfo;
import  com.ygqh.baby.ao.ResultSet;
import  com.ygqh.baby.po.YgReturnOrderDetailOffLine;
import  com.ygqh.baby.mapper.YgReturnOrderDetailOffLineMapper;
import  com.ygqh.baby.service.YgReturnOrderDetailOffLineService;

import  org.springframework.util.Assert;

import java.util.Arrays;

import  org.springframework.stereotype.Service;
import  org.springframework.beans.factory.annotation.Autowired;

import  com.ygqh.baby.po.YgReturnOrderDetailOffLineExample;
import  com.ygqh.baby.ao.DataStatus;

@Service
public class YgReturnOrderDetailOffLineServiceImpl implements YgReturnOrderDetailOffLineService{
	
	@Autowired
	private YgReturnOrderDetailOffLineMapper ygReturnOrderDetailOffLineMapper;
	
	@Override
	public List<YgReturnOrderDetailOffLine> find() {
		YgReturnOrderDetailOffLineExample example = new YgReturnOrderDetailOffLineExample();
		example.createCriteria().andStatusEqualTo(DataStatus.Valid.name());
		return ygReturnOrderDetailOffLineMapper.selectByExample(example);
	}

	@Override
	public int findCount() {
		YgReturnOrderDetailOffLineExample example = new YgReturnOrderDetailOffLineExample();
		example.createCriteria().andStatusEqualTo(DataStatus.Valid.name());
		return ygReturnOrderDetailOffLineMapper.countByExample(example);
	}

	@Override
	public YgReturnOrderDetailOffLine findById(Long id) {
		return ygReturnOrderDetailOffLineMapper.selectByPrimaryKey(id);
	}


	

	@Override
	public int save(YgReturnOrderDetailOffLine ygReturnOrderDetailOffLine) {
		return ygReturnOrderDetailOffLineMapper.insertSelective(ygReturnOrderDetailOffLine);
	}

	@Override
	public int update(YgReturnOrderDetailOffLine ygReturnOrderDetailOffLine) {
		return ygReturnOrderDetailOffLineMapper.updateByPrimaryKeySelective(ygReturnOrderDetailOffLine);
	}

	@Override
	public ResultSet<YgReturnOrderDetailOffLine> search(QueryInfo queryInfo,String q) {
		List<YgReturnOrderDetailOffLine>  list =  ygReturnOrderDetailOffLineMapper.selectSuper(queryInfo, q);
		int count = ygReturnOrderDetailOffLineMapper.countSuper(q);
		ResultSet<YgReturnOrderDetailOffLine> resultSet = new ResultSet<YgReturnOrderDetailOffLine>(count,list);
		return resultSet;
	}

	@Override
	public int deleteSoft(Long[] ids) {
		Assert.notEmpty(ids);
		YgReturnOrderDetailOffLineExample example = new YgReturnOrderDetailOffLineExample();
		example.createCriteria().andIdIn(Arrays.asList(ids));
		YgReturnOrderDetailOffLine record = new YgReturnOrderDetailOffLine();
		record.setStatus(DataStatus.Delete);

		return ygReturnOrderDetailOffLineMapper.updateByExampleSelective(record, example);
	}
	
	@Override
	public int deleteSoft(Long id) {
		return this.deleteSoft(new Long[]{id});
	}

	@Override
	public int saveOrUpdate(YgReturnOrderDetailOffLine ygReturnOrderDetailOffLine) {
		int r = 0;
		if(ygReturnOrderDetailOffLine.getId() != null) {
			r = this.update(ygReturnOrderDetailOffLine);
		}else {
			r = this.save(ygReturnOrderDetailOffLine);
		}
		return r;
	}

	@Override
	public List<YgReturnOrderDetailOffLine> findByReturnCode(String returnCode) {
		YgReturnOrderDetailOffLineExample example = new YgReturnOrderDetailOffLineExample();
		example.createCriteria().andReturnCodeEqualTo(returnCode);
		return ygReturnOrderDetailOffLineMapper.selectByExample(example);
	}

}

